﻿using System.Windows.Forms;
using Business;
using Business.Entity.Contabil.Pessoa.ClassesRelacionadas;
using Business.Entity.Contabil.Pessoa.SubClass.Usuario.ClassesRelacionadas;
using Business.Forms;
using Business.Validation;
using DevExpress.XtraEditors;

namespace Bonesoft.Forms.Contabil
{
    public partial class FormEndereco : FormDefault,IForm
    {
        public FormEndereco()
        {
            InitializeComponent();
            InitFocusControl = cepTextEdit;
        }

        public object Novo()
        {
            PessoaEndereco en = new PessoaEndereco();
            enderecoBindingSource.DataSource = en;
            cepTextEdit.Focus();
            ShowDialog();
            return en;
        }

        public void Alterar(object entity)
        {
            enderecoBindingSource.DataSource = entity;
            cepTextEdit.Focus();
            ShowDialog();
        }

        public object Save()
        {
            throw new System.NotImplementedException();
        }

        public void Update(object entity)
        {
            Alterar(entity);
        }

        public bool Delete(object entity)
        {
            throw new System.NotImplementedException();
        }

        public object CurrentObject
        {
            get
            {
                return enderecoBindingSource.DataSource;
            }
            set
            {
                enderecoBindingSource.DataSource = value;
            }
        }

        public PermissaoForm Permissao
        {
            get
            {
                return null;
            }
        }

        public EntityValidationResult Validate()
        {
            return DataValidation.ValidateEntity(typeof (PessoaEndereco));
        }

        public void Reload()
        {
            
        }

        public void Cancel()
        {
            if (Validate().HasError)
            {
                DialogResult = DialogResult.Cancel;
            }
            Close();
        }

        public object New()
        {
            return Novo();
        }

        public XtraForm Form
        {
            get
            {
                return this;
            }
        }

        public FormState FormState { get; set; }
    }
}